<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\UserAccount;
use App\Models\Users;
use App\Services\UserHutongService;
use Illuminate\Http\Request;

class WanSdkController extends Controller
{
    // 基于微信（不是小程序，不是小游戏）打开游戏
    // 通过user绑定官方账号
    // 返回给到前端进行实名认证操作
    public function getAccountInfo(Request $request)
    {
        $user_id = $request->input('user_id');
        $user = Users::find($user_id);

        $bind = UserHutongService::getInstance()->getOrCreateAccountBind($user->channel, $user->channel_openid);
        if (!$bind) {
            return yqerr(6044);
        }

        $user_account = UserAccount::where('openid', $bind->account_openid)->first();
        return yqok($user_account->toArray());
    }
}
